<!DOCTYPE html>
<html>
<head>
    <title>slave1</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="../src/cross-domain.js"></script>
</head>
<body>
<div id="main">
    I am salve1 frame
    <button onclick="sendMesg()">send data to MASTER</button>
</div>
<div id="content"></div>
</body>
<script type="text/javascript">
    var me = CD.component.name;
    function genInfo(name) {
        return {info: "Hello [" + name + "] , I am [" + me + "] Now at " + new Date()};
    }

    //调用MASTER的changeMaster接口，数据参数是genInfo("MESTER")
    function sendMesg(argument) {
        CD.send("MESTER", "changeMaster", genInfo("MESTER"));
    }

    //提供给其它iframe的接口，接口名changeSlave1
    CD.extends("changeSlave1", function (data) {
        writeHtml(data.info);
        //接口返回值，会触发调用方的回调函数
        return "Slave1 changeSlave1 is called";
    });
    function writeHtml(text) {
        var content = document.getElementById("content");
        content.innerHTML += "<br/>" + text;
    }
    console.log(CD);
</script>

</html>
